import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: ttq
 * Date: 13-7-4
 * Time: 下午2:14
 * To change this template use File | Settings | File Templates.
 */
public class ImageRedirectFilter implements Filter {
    public void init(FilterConfig config) throws SecurityException {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request1 = (HttpServletRequest) request;
        HttpServletResponse response1 = (HttpServletResponse) response;
        String referer = request1.getHeader("referer");
        if (referer == null || !referer.contains(request1.getServerName())) {
            request1.getRequestDispatcher("/error.gif").forward(request1, response1);
        }
        else
        {
            chain.doFilter(request1,response1);
        }
    }

    public  void  destroy()
    {
    }
}
